package com.shenmazong.label.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shenmazong.label.entity.TbExamLabel;
import com.shenmazong.label.entity.TbExamLabelType;
import com.shenmazong.label.mapper.TbExamLabelTypeMapper;
import com.shenmazong.label.service.ExamLabelService;
import com.shenmazong.label.mapper.TbExamLabelMapper;
import com.shenmazong.util.ChooseIsNull;
import com.shenmazong.utils.ResultResponse;
import com.shenmazong.vo.BatchChooseIdVo;
import com.shenmazong.vo.ExamCheatVo;
import com.shenmazong.vo.ListParamVo;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 *serviceImpl Qi
 */
@Service
public class ExamLabelServiceImpl extends ServiceImpl<TbExamLabelMapper, TbExamLabel>
    implements ExamLabelService {

    @Autowired
    private  TbExamLabelMapper  labelMapper;
    @Autowired
    private TbExamLabelTypeMapper   typeMapper;


    @Override
    public ResultResponse saveExamLabel(TbExamLabel tbExamLabel) {
        int i = labelMapper.insert(tbExamLabel);
        if(i<1){
            return ResultResponse.FAILED("新增失败");
        }
        return ResultResponse.SUCCESS(labelMapper.selectById(tbExamLabel.getLabelId()));
    }

    @Override
    public ResultResponse deleteExamLabel(BatchChooseIdVo chooseIdVo) {
        if (ChooseIsNull.idsIsNull(chooseIdVo)){
            return ResultResponse.FAILED("未选择要删除的数据");
        }
        int i = labelMapper.deleteBatchIds(chooseIdVo.getIds());
        if(i<1){
            return ResultResponse.FAILED("删除失败");
        }
        return ResultResponse.SUCCESS();
    }

    @Override
    public ResultResponse updateExamLabel(TbExamLabel tbExamLabel) {
        int i = labelMapper.updateById(tbExamLabel);
        if(i<1){
            return ResultResponse.FAILED("修改失败");
        }
        return ResultResponse.SUCCESS(labelMapper.selectById(tbExamLabel.getLabelId()));
    }

    @Override
    public ResultResponse listExamLabel(ListParamVo paramVo) {
        //非空判断
        if(paramVo.getParamMap().size()==0 || paramVo.getParamMap().get("schoolId")==null){
            return ResultResponse.FAILED("无效查询条件");
        }

        IPage<TbExamLabel> page = new Page<>(paramVo.getCurrent(), paramVo.getSize());
        IPage<TbExamLabel> selectPage = labelMapper.selectPage(page,null);
        return ResultResponse.SUCCESS(selectPage);
    }

    @Override
    public ResultResponse listAllExamLabel() {
        return ResultResponse.SUCCESS(labelMapper.selectList(null));
    }

    @Override
    public ResultResponse saveExamLabelType(TbExamLabelType tbExamLabelType) {
        int i = typeMapper.insert(tbExamLabelType);
        if(i<1){
            return ResultResponse.FAILED("新增失败");
        }
        return ResultResponse.SUCCESS(typeMapper.selectById(tbExamLabelType.getLabelTypeId()));
    }

    @Override
    public ResultResponse deleteExamLabelType(BatchChooseIdVo chooseIdVo) {
        if (ChooseIsNull.idsIsNull(chooseIdVo)){
            return ResultResponse.FAILED("未选择要删除的数据");
        }
        int i = typeMapper.deleteBatchIds(chooseIdVo.getIds());
        if(i<1){
            return ResultResponse.FAILED("删除失败");
        }
        return ResultResponse.SUCCESS();
    }

    @Override
    public ResultResponse updateExamLabelType(TbExamLabelType tbExamLabelType) {
        int i = typeMapper.updateById(tbExamLabelType);
        if(i<1){
            return ResultResponse.FAILED("修改失败");
        }
        return ResultResponse.SUCCESS(typeMapper.selectById(tbExamLabelType.getLabelTypeId()));
    }

    @Override
    public ResultResponse listExamLabelType(ListParamVo paramVo) {
        //非空判断
        if(paramVo.getParamMap().size()==0 || paramVo.getParamMap().get("schoolId")==null){
            return ResultResponse.FAILED("无效查询条件");
        }

        IPage<TbExamLabelType> page = new Page<>(paramVo.getCurrent(), paramVo.getSize());
        IPage<TbExamLabelType> selectPage = typeMapper.selectPage(page,null);
        return ResultResponse.SUCCESS(selectPage);
    }

    @Override
    public ResultResponse listAllExamLabelType() {
        return ResultResponse.SUCCESS(typeMapper.selectList(null));
    }
}




